{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import time\n",
    "import random\n",
    "from selenium import webdriver\n",
    "from selenium.webdriver.edge.service import Service\n",
    "from selenium.webdriver.common.by import By\n",
    "from selenium.webdriver import ActionChains\n",
    "\n",
    "\n",
    "driver_path = \"C:/Users/26449/msedgedriver.exe\"  \n",
    "\n",
    "service = Service(executable_path=driver_path)\n",
    "driver = webdriver.Edge(service=service)\n",
    "\n",
    "# 打开登录页面\n",
    "driver.get(\"https://www.digquant.com/account\") \n",
    "\n",
    "# 等待页面加载完成（根据实际情况调整等待时间，如3-5秒）\n",
    "time.sleep(3)  # 等待3秒，确保页面元素加载完毕\n",
    "\n",
    "\n",
    "def simulate_sendkeys(label, str1):\n",
    "    label.clear()\n",
    "    time.sleep(0.5)\n",
    "    for i in str1:\n",
    "        time.sleep(random.random())\n",
    "        label.send_keys(i)\n",
    "    time.sleep(0.5)\n",
    "\n",
    "# 读取配置文件\n",
    "with open(\"D:/桌面/信息.json\", \"r\", encoding=\"utf-8\") as f:\n",
    "    config = json.load(f)\n",
    "    account = config[\"account\"]\n",
    "    password = config[\"password\"]\n",
    "\n",
    "# 定位账号输入框并输入\n",
    "a = driver.find_element(By.XPATH,\"/html/body/div[1]/div[2]/div[1]/div/div[2]/div/div[2]/form/div[1]/div/div/div/input\")\n",
    "simulate_sendkeys(a, account)\n",
    "\n",
    "# 定位密码输入框并输入\n",
    "b = driver.find_element(By.XPATH,\"/html/body/div[1]/div[2]/div[1]/div/div[2]/div/div[2]/form/div[2]/div/div/div/input\")\n",
    "simulate_sendkeys(b, password)\n",
    "\n",
    "# 定位登录按钮并点击\n",
    "c = ActionChains(driver)\n",
    "d = driver.find_element(By.XPATH,\"/html/body/div[1]/div[2]/div[1]/div/div[2]/div/div[2]/form/div[3]\")\n",
    "c.click(d).perform()\n",
    "\n",
    "time.sleep(10)  # 等待10秒\n",
    "driver.quit()  # 关闭浏览器\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
